<?php
include(dirname(__FILE__) . "/../../../include/global.php");

function getrvalue($id,$hostname,$snmp_community){
	$model = db_fetch_cell('SELECT oid_get FROM plugin_nms_oid WHERE descrip = "physicalname"');
	$name = db_fetch_cell('SELECT oid_get FROM plugin_nms_oid WHERE descrip = "getname"');
	$rvalue = db_fetch_cell('SELECT oid_get FROM plugin_nms_oid WHERE descrip = "rvalue"');
	$thold = db_fetch_cell('SELECT oid_get FROM plugin_nms_oid WHERE descrip = "thold"');
	//remove old data
	db_execute('Update plugin_nms_interface SET rvalue="Unknown", thold=0 Where host_id = '.$id.'');
	$snmp2 = snmp2_real_walk($hostname,$snmp_community,$model);
	foreach($snmp2 as $x=>$x_value){
		$oid = str_replace("SNMPv2-SMI::mib-2.47.1.1.1.1.7.",'',$x);
		$model = trim(str_replace("STRING: ",'',$x_value),'""');
		if($model != ""){
			$oid = str_replace("SNMPv2-SMI::mib-2.47.1.1.1.1.7.",'',$x);
			$result = trim(str_replace("STRING: ",'',$x_value),'""');
			$exp = explode(" ",$result);
			if($exp[1] == 'Receive'){
				//get recive vaule
				$getvalue = snmp2_get($hostname,$snmp_community,$rvalue.'.'.$oid);
				$getvalue = explode(" ",$getvalue);
				$getrvaule = (((int) $getvalue[1])/10);
				// get threshold
				$getthold=0;
				for($i=1;$i<=4;$i++){
					$temp =snmp2_get($hostname,$snmp_community,$thold.'.'.$oid.'.'.$i);
					$temp = explode(" ",$temp);
					if($temp[1] == '1'){
						$getthold = $i;
					}
				}
				if($getrvaule !=''){
					db_execute('UPDATE plugin_nms_interface SET rvalue = "'.$getrvaule.'",thold='.$getthold.'
										WHERE host_id = '.$id.' and interface_name = "'.$exp[0].'"');
				}
			}
		}
	}
}
$id = db_fetch_assoc('SELECT id,hostname,snmp_community FROM host WHERE status != 1 group by id');
$tstart = date('h:i:s');
foreach($id as $item){
	getrvalue($item['id'],$item['hostname'],$item['snmp_community']);
}
$tend = date('h:i:s');
cacti_log('Network Monitoring System: Time get receive value of transcievers start: '.$tstart.' end: '.$tend.' ','NMS');
?>
